$(function() {
    //各种正则
    var patternPhone = /^1[34578]\d{9}$/; 
    var patternpsd = /^[0-9a-zA-Z_]{6,15}$/;
    var patternemail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
   var patternName=/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;
    var flag;
    //验证手机号
$("#phoneinput").blur(function(){
if($("#phoneinput").val()==""){
    $("#phonespan").css("color","red");
    $("#phonespan").text("请输入手机号！");
    flag = false;
}else if(!patternPhone.test( $("#phoneinput").val())){
    $("#phonespan").css("color","red");
    $("#phonespan").text("手机号不符合规则！");
    flag = false;
}else{
    $("#phonespan").css("color","green");
    $("#phonespan").text("✔");
    flag = true;
}
})
//验证密码
$("#psdinput").blur(function(){
if($("#psdinput").val()==""){
    $("#psdspan").css("color","red");
    $("#psdspan").text("请输入密码！");
    flag = false;
}else if(!patternpsd.test( $("#psdinput").val())){
    $("#psdspan").css("color","red");
    $("#psdspan").text("密码不符合规则！(6~15数字大小写字母");
    flag = false;
}else{
    $("#psdspan").css("color","green");
    $("#psdspan").text("✔");
    flag = true;
}
})

//确认密码

$("#confpsdinput").blur(function(){
    if($("#confpsdinput").val()==""){
        $("#confpsdspan").css("color","red");
        $("#confpsdspan").text("请输入密码！");
        flag = false;
    }else if(!$("#confpsdinput").val==$("#psdinput").val()){
        $("#confpsdspan").css("color","red");
        $("#confpsdspan").text("密码不匹配！");
        flag = false;
    }else{
        $("#confpsdspan").css("color","green");
        $("#confpsdspan").text("✔");
        flag = true;
    }
    })


 //验证邮箱
 $("#emailinput").blur(function(){
    if($("#emailinput").val()==""){
        $("#emailspan").css("color","red");
        $("#emailspan").text("请输入邮箱！");
        flag = false;
    }else if(!patternemail.test( $("#emailinput").val())){
        $("#emailspan").css("color","red");
        $("#emailspan").text("邮箱不符合规则！");
        flag = false;
    }else{
        $("#emailspan").css("color","green");
        $("#emailspan").text("✔");
        flag = true;
    }
    })


//验证人名
$("#nameinput").blur(function(){
    if($("#nameinput").val()==""){
        $("#namespan").css("color","red");
        $("#namespan").text("请输入姓名！");
        flag = false;
    }else if(!patternName.test( $("#nameinput").val())){
        $("#namespan").css("color","red");
        $("#namespan").text("姓名不符合规则！");
        flag = false;
    }else{
        $("#namespan").css("color","green");
        $("#namespan").text("✔");
        flag = true;
    }
    })


//验证生日
$("#birdateinput").blur(function(){

  var birthday = $("#birdateinput").val();
  var date = new Date(birthday);
  var now = new Date();

    if($("#birdateinput").val()==""){
        $("#birdatespan").css("color","red");
        $("#birdatespan").text("请输入生日！");
        flag = false;
    }else if(now.getFullYear()-date.getFullYear()<=18){
        $("#birdatespan").css("color","red");
        $("#birdatespan").text("未满18禁止注册！");
        flag = false;
    }else{
        $("#birdatespan").css("color","green");
        $("#birdatespan").text("✔");
        flag = true;
    }
    })

//全选
$("#allchoose").click(function () { 
   if($(".ability").is(":checked")){
    $(".ability").prop("checked",false);
   }else{
    $(".ability").prop("checked",true);
   }
    
});

//反选
$("#inversechoose").click(function () { 
   $(".ability").each(
       function(){
        if($(this).is(":checked")){
            $(this).prop("checked",false);
           }else{
            $(this).prop("checked",true);
           }
       }
   )   
 });

//三级


var provinces=[{id:"0",name:"安徽"},
                {id:"1",name:"江苏"},
]
var cities=[
                [{id:"0",name:"合肥",level:1},{id:"1",name:"六安",level:1},],

                [{id:"2",name:"无锡",level:1},{id:"3",name:"南京",level:1}]
              
            ]

var qu=[
                [{id:0,name:"蜀山"},{id:1,name:"瑶海"}],
                [{id:2,name:"金安"},{id:3,name:"裕安区"}],
                [{id:4,name:"梁溪"},{id:5,name:"惠山"}],
                [{id:6,name:"鼓楼区"},{id:7,name:"玄武区"}]



]

$(provinces).each(function(index,province){
    $('#shen').append('<option value='+province.id+'>'+province.name+'</option>');
})

$('#shen').change(function(){
  let provincesId=Number($(this).val());
 $('#shi').empty();
   $('#shi').append('<option >'+"市/地区/自治州/盟"+'</option>');
  $(cities[provincesId]).each(function(index,city){
    $('#shi').append('<option value='+city.id+'>'+city.name+'</option>');
    
})  
})

$('#shi').change(function(){
    $('#qu').empty();
    $('#qu').append('<option >'+"区/县/旗"+'</option>');
    $(qu[$(this).val()]).each(function(index,qu){
        $('#qu').append('<option value='+qu.id+'>'+qu.name+'</option>');
       
    })  



})










//条款
 $("input[name='isAgree']").click(function(){
    if($(this).is(":checked")){
        flag=true
    }else{
        flag=false
    }
 })




 $("#tijiao").click(function(){
    console.log(flag);
 })


})